<template>
  <div class="login">
    <!-- 左边内容 -->
    <div class="left">
      <div class="top">
        <img class="logo" src="../../assets/img/login_logo.png" alt="" />
        <span class="t1">黑马面面</span>
        <div class="linear"></div>
        <span class="t2">用户登录</span>
      </div>
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item prop="phone">
          <el-input
            placeholder="请输入手机号码"
            prefix-icon="el-icon-user"
            v-model="form.phone"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            show-password
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            v-model="form.password"
          ></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-row>
            <el-col :span="16">
              <el-input
                placeholder="请输入验证码"
                prefix-icon="el-icon-key"
                v-model="form.code"
              ></el-input>
            </el-col>
            <el-col :span="8">
              <img class="code" src="../../assets/img/code.jpg" alt="" />
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item prop="isCheck">
          <el-checkbox v-model="form.isCheck"
            >我已阅读并同意 <el-link type="primary">用户协议</el-link>
            和
            <el-link type="primary">隐私条款</el-link>
          </el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="submit"
            >登录</el-button
          >
          <br />
          <el-button style="width: 100%" class="btn" @click="zhuche"
            >注册</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 右边图片 -->
    <img src="../../assets/img/login_banner_ele.png" alt="" />
    <!-- 弹框 -->
    <Storng ref="register"></Storng>
  </div>
</template>

<script>
import Storng from './storng.vue'
export default {
  components: {
    Storng
  },
  data () {
    return {
      form: {
        phone: '',
        password: '',
        code: '',
        isCheck: []
      },
      rules: {
        phone: [
          { required: true, message: '请填入手机号！', trigger: 'change' }
        ],
        password: [
          { required: true, message: '请填入密码！', trigger: 'change' },
          {
            min: 6,
            max: 12,
            message: '请输入6-12位密码！',
            trigger: 'change'
          }
        ],
        code: [
          { required: true, message: '请填入验证码！', trigger: 'change' },
          {
            required: true,
            min: 4,
            max: 4,
            message: '请填写正确验证码！',
            trigger: 'change'
          },
          {
            validator: (rules, value, callback) => {
              const reg = /^\d{4}$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('请输入正确验证码'))
              }
            },
            trigger: 'change'
          }
        ],
        isCheck: [{ required: true, message: '必勾项！', trigger: 'change' }]
      }
    }
  },
  methods: {
    /* 登录 */
    submit () {
      this.$refs.form.validate(value => {
        if (value) {
          this.$message.success('登录成功')
        } else {
          this.$message.error('登录失败')
        }
      })
    },
    /* 注册 */
    zhuche () {
      this.$refs.register.isShow = true
    }
  }
}
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  background: linear-gradient(225deg, #01c6fa 4%, #1493fa 72%);
  display: flex;
  align-items: center;
  justify-content: space-around;
  .left {
    width: 478px;
    height: 550px;
    background: #f5f5f5;
    padding: 42px;
    .top {
      display: flex;
      align-items: center;
      margin-bottom: 30px;
      .logo {
        width: 22px;
        height: 17px;
      }
      .t1 {
        font-size: 24px;
        margin: 0px 16px;
      }
      .linear {
        width: 2px;
        height: 28px;
        background: #c7c7c7;
      }
      .t2 {
        margin-left: 12px;
        font-size: 22px;
      }
    }
    .code {
      width: 100%;
      height: 42px;
    }
    .btn {
      margin-top: 26px;
    }
  }
  ::v-deep .el-form-item__content {
    line-height: 0px;
    position: relative;
    font-size: 14px;
  }
  ::v-deep .el-input__inner {
    height: 45px;
    line-height: 45px;
  }
}
</style>
